﻿using System.Text;

namespace PMS.WebApi.Extensions
{
    public static class HttpResponseMessageEx
    {
        public static HttpResponseMessage ToJson(this object obj)
        {
            string str = string.Empty;
            if (obj is String || obj is Char)
            {
                str = obj.ToString();
            }
            else
            {
                str = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
            }
            HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
            return result;
        }
    }
}
